home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / hc2_x / tcprogud.sit / TC Prog Guide / card_41536.txt < prev    next >
Text File  |  1991-02-27  |  2KB  |  98 lines

  1. -- card: 41536 from stack: in
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 4755
  5. -- name: 
  6.  
  7.  
  8. -- part 1 (field)
  9. -- low flags: 00
  10. -- high flags: 0007
  11. -- rect: left=30 top=78 right=296 bottom=478
  12. -- title width / last selected line: 0
  13. -- icon id / first selected line: 0 / 0
  14. -- text alignment: 0
  15. -- font id: 4
  16. -- text size: 9
  17. -- style flags: 0
  18. -- line height: 12
  19. -- part name: 
  20.  
  21.  
  22. -- part contents for card part 1
  23. ----- text -----
  24. /*
  25. *   FILE:    person.c
  26. *   AUTHOR:  R.G.
  27. *   CREATED: June 25, 1990
  28. *   
  29. *   define Person methods
  30. */
  31.  
  32. # include "person.h"
  33. # include <stdio.h>      /* declares printf(), scanf() */
  34. # include <string.h>     /* declares strlen(), strcpy() */
  35. # include <stdlib.h>     /* declares malloc(), free() */
  36.  
  37. /******************************************************************
  38. *   override init()
  39. ******************************************************************/
  40. int     Person::init(void)
  41. {
  42.     name = NULL;   /* NULL pointer points "nowhere" */
  43.     return 1;
  44. }
  45.  
  46. /******************************************************************
  47. *   set Person
  48. ******************************************************************/
  49. void    Person::set(void)
  50. {
  51.     char    temp_name[80];
  52.     int     temp_age;
  53.  
  54.     printf("Enter name (no spaces):\n");
  55.     scanf("%s",temp_name);
  56.  
  57. /*  malloc allocates space for string plus '\0' null character,
  58. *   if available (else returns NULL):
  59. */
  60.     name = malloc(sizeof(char) * (strlen(temp_name)+1));
  61.     if (name != NULL)
  62.         strcpy(name,temp_name);  /* TC "shadowing" not needed since
  63.                                     dynamic allocation was used  */
  64.  
  65.     printf("Enter age:\n");
  66.     scanf("%d",&temp_age);    /* "shadowing" for TC safety */
  67.     age = temp_age;
  68. }
  69.  
  70. /******************************************************************
  71. *   print Person
  72. ******************************************************************/
  73. void    Person::print(void)
  74. {
  75.     printf("Name: %s, Age: %d",name,age);
  76. }
  77.  
  78. /******************************************************************
  79. *   destroy Person
  80. ******************************************************************/
  81. int     Person::destroy(void)
  82. {
  83.     if (name != NULL)
  84.         free(name);    /* deallocate memory previously allocated */
  85.     return 1;
  86. }
  87.  
  88.  
  89.  
  90.  
  91.  
  92. -- part contents for background part 7
  93. ----- text -----
  94. 134
  95.  
  96. -- part contents for background part 4
  97. ----- text -----
  98. File 4 of 7: